package com.bocloud.cmp.driver.providers.os;

import java.util.List;

import org.openstack4j.model.telemetry.Alarm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.bocloud.cmp.driver.convertor.BeanConvert;
import com.bocloud.cmp.driver.convertor.os.ConvertAlarm;
import com.bocloud.cmp.driver.providers.AlarmDriver;
import com.bocloud.cmp.model.AlarmModel;
import com.bocloud.common.model.BsmResult;
import com.google.common.collect.Lists;

public class OSAlarmDriver extends OSDriver implements AlarmDriver {

	private static final Logger logger = LoggerFactory.getLogger(OSAlarmDriver.class);

	/**
	 * 
	 */
	public OSAlarmDriver() {
		super();
	}

	public OSAlarmDriver(String endpoint, String username, String password, String tenant, String domain,
			String project, Version version) {
		super(endpoint, username, password, tenant, domain, project, version);
	}

	@Override
	public BsmResult sync() {
		List<? extends Alarm> alarms = Lists.newArrayList();
		if (!this.accessable()) {
			logger.error(this.getError());
			return new BsmResult(false, this.getError());
		}
		alarms = this.getClient().telemetry().alarms().list();
		List<AlarmModel> models = Lists.newArrayList();
		if (null != alarms) {
			BeanConvert<AlarmModel, Alarm> convertAlarm = new ConvertAlarm();
			models = convertAlarm.convertList(alarms);
			return new BsmResult(true, models, "success");
		}
		return new BsmResult(false, "failed");
	}

}
